package com.ruoyi.web.controller.basic;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BasicMessageTemplate;
import com.ruoyi.system.service.IBasicMessageTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息模板Controller
 * 
 * @author ruoyi
 * @date 2025-03-02
 */
@RestController
@RequestMapping("/system/basicMessageTemplate")
public class BasicMessageTemplateController extends BaseController
{
    @Autowired
    private IBasicMessageTemplateService basicMessageTemplateService;

    /**
     * 查询消息模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicMessageTemplate basicMessageTemplate)
    {
        startPage();
        List<BasicMessageTemplate> list = basicMessageTemplateService.selectBasicMessageTemplateList(basicMessageTemplate);
        return getDataTable(list);
    }

    /**
     * 导出消息模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageTemplate:export')")
    @Log(title = "消息模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicMessageTemplate basicMessageTemplate)
    {
        List<BasicMessageTemplate> list = basicMessageTemplateService.selectBasicMessageTemplateList(basicMessageTemplate);
        ExcelUtil<BasicMessageTemplate> util = new ExcelUtil<BasicMessageTemplate>(BasicMessageTemplate.class);
        util.exportExcel(response, list, "消息模板数据");
    }

    /**
     * 获取消息模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageTemplate:query')")
    @GetMapping(value = "/{messageTemplateId}")
    public AjaxResult getInfo(@PathVariable("messageTemplateId") Long messageTemplateId)
    {
        return success(basicMessageTemplateService.selectBasicMessageTemplateByMessageTemplateId(messageTemplateId));
    }

    /**
     * 新增消息模板
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageTemplate:add')")
    @Log(title = "消息模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicMessageTemplate basicMessageTemplate)
    {
        return toAjax(basicMessageTemplateService.insertBasicMessageTemplate(basicMessageTemplate));
    }

    /**
     * 修改消息模板
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageTemplate:edit')")
    @Log(title = "消息模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicMessageTemplate basicMessageTemplate)
    {
        return toAjax(basicMessageTemplateService.updateBasicMessageTemplate(basicMessageTemplate));
    }

    /**
     * 删除消息模板
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageTemplate:remove')")
    @Log(title = "消息模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageTemplateIds}")
    public AjaxResult remove(@PathVariable Long[] messageTemplateIds)
    {
        return toAjax(basicMessageTemplateService.deleteBasicMessageTemplateByMessageTemplateIds(messageTemplateIds));
    }
}
